package com.study.rabbitmq.producer.basic;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;


public class Send {
	private final static String QUEUE_NAME = "tanQueue";
	private final  static  String EXCHANGE_NAME = "tanExchange";

	private final  static  String ROUTING_KEY = "tan";

	public static void main(String[] args) throws Exception {
		ConnectionFactory factory = new ConnectionFactory();
		factory.setHost("192.168.20.204");
		factory.setPort(5673);
		factory.setUsername("tan");
		factory.setPassword("tan");

		Connection connection = factory.newConnection();
		Channel channel = connection.createChannel();

		channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT,true,false,null);

		channel.queueDeclare(QUEUE_NAME, true, false, false, null);


		channel.queueBind(QUEUE_NAME,EXCHANGE_NAME,ROUTING_KEY);


		String message = "Hello wrorld";

		for (int i=0; i<100; i++){
			channel.basicPublish(EXCHANGE_NAME, ROUTING_KEY, null, (message+i).getBytes());
			System.out.println(i);
		}

		channel.close();
		connection.close();
	}
}
